﻿using System;
using System.Data;
using System.Threading;
using System.Threading.Tasks;

namespace Currency.Infra.IRepository
{
    /// <summary>
    /// 事物接口
    /// </summary>
    public interface IUnitOfWork : IDisposable
    {
        /// <summary>
        /// 启用事物
        /// </summary>
        /// <param name="isolationLevel">事物隔离等级</param>
        /// <param name="sharedToCap">CAP是否启用</param>
        void BeginTransaction(IsolationLevel isolationLevel = IsolationLevel.RepeatableRead, bool sharedToCap = false);

        /// <summary>
        /// 回滚
        /// </summary>
        void Rollback();

        /// <summary>
        /// 提交
        /// </summary>
        void Commit();

        /// <summary>
        /// 异步回滚
        /// </summary>
        /// <param name="cancellationToken">取消标记</param>
        /// <returns></returns>
        Task RollbackAsync(CancellationToken cancellationToken = default);

        /// <summary>
        /// 异步提交
        /// </summary>
        /// <param name="cancellationToken">取消标记</param>
        /// <returns></returns>
        Task CommitAsync(CancellationToken cancellationToken = default);
    }
}
